| SP_CODE | COMMON.NAME | SPECIES |
|---|---|---|
| AGCL | Shotgun Kelp | Agarum clathratum |
| AGJ | Juv. Shotgun Kelp | Agarum clathratum |
| CAIS | Atlantic Rock Crab | Cancer irroratus |
| CEBO | Northern cerianthid | Pachycerianthus borealis |
| COPE | Sea Potato | Colpomenia peregrina |
| DEAC | Sour or Stink Weed | Desmarestia aculeata |
| ECPA | common sand dollar | Echinarachnius parma |
| HATO | Hairy Shoelace | Halosiphon tomentosus |
| HESA | Blood Star | Henricia sanguinolenta |
| HESAS | Blood Star | Henricia sanguinolenta |
| HOAM | American lobster | Homarus americanus |
| HOAS | American lobster | Homarus americanus |
| MYSP | Sculpin | Myoxocephalus |
| PHGU | Rock gunnel | Pholis gunnellus |
| SADE | Oarweed | Saccorhiza dermatodea |
| SDL | Green Sea Urchin | Strongylocentrotus droebachiensis |
| SDS | Green Sea Urchin | Strongylocentrotus droebachiensis |
| SL | Sugar Kelp | Saccharina latissima |
| SLJ | Juvenile Sugar Kelp | Saccharina latissima |
Here are some functions we’ll apply to each species. I’ll then fit mixed models with all of them using
with a gaussian error. Note, it’s count, so, I could use Poisson, but, that needs to be way more tuned to each model - this should be fine for a first cut?
Here’s how we’ll do it:
tseries_plot <- function(adf){
ggplot(adf,
aes(y = COUNT, x = YEAR,
color = TRANSECT)) +
stat_summary(fun.data = mean_se) +
stat_summary(fun.data = mean_se, geom = "line") +
facet_wrap(~SITE, nrow = 2) +
labs(color = "Transect",
y = "Count per sq m ± SE", x = "Year",
title = adf$SPECIES[1])
}
tseries_fun <- function(adf){
glmmTMB(COUNT ~ YEAR * SITE + (1|TRANSECT),
data = adf,
family = gaussian)
}
generate_output <- function(adf){
cat(paste0("## ", adf$SP_CODE[1], " ", adf$SPECIES[1], " \n<br>"))
tseries_plot(adf) %>% print()
# tseries_fun(adf) %>%
# car::Anova(test.statistic = "Chisq") %>%
# tidy() %>%
# knitr::kable("html", digits = 3) %>%
# kableExtra::kable_styling() %>%
# print
#
cat("\n\n")
}
Now let’s purrr::walk() through the whole shebang.
walk(split(quad, quad$SP_CODE), generate_output)